package ntd.util;

import cn.hutool.core.io.IoUtil;
import cn.hutool.log.Log;
import cn.hutool.log.StaticLog;

import java.io.InputStream;

/**
 * 命令执行工具类
 */
public class UtilProcess {

    private static String run(String str) {
        try {
            Process p = Runtime.getRuntime().exec(str);//创建实例进程执行命令行代码
            p.waitFor();
            final InputStream inputStream = p.getInputStream();
            final String read = IoUtil.read(inputStream, "gbk");
            p.destroy();
            return read;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    public static void main(String[] args){
        StaticLog.error(run("ipconfig"));
    }

}
